package com.spzx.cart.api;

import com.spzx.cart.api.domain.CartInfo;
import com.spzx.cart.api.factory.RemoteCartFallbackFactory;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;


@FeignClient(value = ServiceNameConstants.CART_SERVICE,
        fallbackFactory = RemoteCartFallbackFactory.class)
public interface RemoteCartService {
    /**
     * 返回购物车选中商品列表
     * @return
     */
    @GetMapping("/getCartCheckedList")
    R<List<CartInfo>> getCartCheckedList (
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );

    /**
     * 更新用户购物车中选中商品为最新价格
     * 防止支付的时候，付的不是最新的价格
     * @param userId
     * @return
     */
    @GetMapping("/updateCartPrice/{userId}")
    R<Boolean> updateCartPrice(@PathVariable("userId") Long userId,
    @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 在用户支付了选中的购物车商品后，删除选中商品
     * @param userId
     * @return
     */
    @GetMapping("/deleteCartCheckedList/{userId}")
    R<Boolean> deleteCartCheckedList(@PathVariable("userId") Long userId,
     @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
